package com.lishe.lishe.lishe.module.mall.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.mall.adapter.GoodsPromotionAdapter;
import com.lishe.lishe.lishe.module.mall.bean.MallGoods;

/**
 * 商品促销信息弹窗
 * @author Bin
 */
public class GoodsPromotionDialog extends Dialog implements View.OnClickListener {

	private Context context;
	private SparseArray<MallGoods.Discount> mPromotionList;

	public GoodsPromotionDialog(Context context, SparseArray<MallGoods.Discount> list) {
		super(context, R.style.SimpleBottomDialog);
		this.context = context;
		this.mPromotionList = list;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_goodspromotion);
		Window dialogWindow = this.getWindow();
		dialogWindow.setGravity(Gravity.BOTTOM);

		Display display = dialogWindow.getWindowManager().getDefaultDisplay();
		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
		lp.width = display.getWidth();
		dialogWindow.setAttributes(lp);

		//设置点击Dialog外部任意区域关闭Dialog
		setCanceledOnTouchOutside(true);

		RecyclerView mRecyclerView = findViewById(R.id.recyclerview);
		mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
		mRecyclerView.setAdapter(new GoodsPromotionAdapter(mPromotionList));

		findViewById(R.id.cancel).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		dismiss();
	}

}
